import type { RouteRecordRaw } from 'vue-router'
import { touteList } from './router-dataConfig'

function getList(list:any){
  const result = list.map((item:any) => {
    const nameArr = item.name.split('.')
    item.path = nameArr[nameArr.length-1]
    if(item.children && item.children.length>0){
      item.children = item.children.map((item1:any) => {
        const nameArr1 = item1.name.split('.')
        item1.path = nameArr1[nameArr1.length-1]
        return item1
      })
    }
    return item
  });
  return result
}

const resuteList = getList(touteList)

export const constantRoute: RouteRecordRaw[] = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '',
      hidden: false,
      icon: '',
    },
  },
  {
    path: '/',
    name: 'layout',
    component: () => import('@/layout/Layout.vue'),
    redirect: '/menu',
    children: resuteList,
  },
]

//异步路由
export const asnycRoute: RouteRecordRaw[] = []

//任意路由
export const anyRoute: RouteRecordRaw = {
  //任意路由
  path: '/:pathMatch(.*)*',
  redirect: '/login',
  name: 'Any',
  meta: {
    title: '任意路由',
    hidden: true,
    icon: 'DataLine',
  },
}
